package com.shenmazong.serverwebpoem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shenmazong.serverwebpoem.mapper.ITbTranslateMapper;
import com.shenmazong.serverwebpoem.pojo.TbTranslate;
import com.shenmazong.serverwebpoem.service.TbTranslateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 田不平
 * @project server-web-poem
 * @date 2020/3/23 9:11 PM
 * http://www.shenmazong.com
 */

@Service
public class TbTranslateServiceImpl implements TbTranslateService {
    @Autowired
    ITbTranslateMapper iTbTranslateMapper;

    @Override
    public void add(TbTranslate translate) {
        iTbTranslateMapper.insert(translate);
    }

    @Override
    public void del(Integer id) {
        iTbTranslateMapper.deleteById(id);
    }

    @Override
    public void set(TbTranslate story) {
        iTbTranslateMapper.updateById(story);
    }

    @Override
    public TbTranslate getById(Integer id) {
        return iTbTranslateMapper.selectById(id);
    }

    @Override
    public List<TbTranslate> getByPoetryId(Integer id) {

        Map<String,Object> columnMap = new HashMap<>();
        columnMap.put("poetryid", id);
        List<TbTranslate> stories = iTbTranslateMapper.selectByMap(columnMap);

        return stories;
    }

    @Override
    public IPage<TbTranslate> getNoteByPage(Integer pageCurrent, Integer pageSize) {
        QueryWrapper<TbTranslate> queryWrapper = new QueryWrapper<>();
        //queryWrapper.eq("authorid", authorId);
        queryWrapper.orderByAsc("verify");
        queryWrapper.orderByDesc("id");

        Page<TbTranslate> page = new Page<>(pageCurrent, pageSize);
        IPage<TbTranslate> iPage = iTbTranslateMapper.selectPage(page, queryWrapper);
        System.out.println("总页数:"+iPage.getPages());
        System.out.println("总记录数:"+iPage.getTotal());

        return iPage;
    }
}
